INCLUDE(${QT_USE_FILE})

FILE( GLOB sources RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp *.h *.cu )
INCLUDE_DIRECTORIES( ${PROJECT_SOURCE_DIR} )

ADD_DEFINITIONS( -DOZ_EXPORTS -D__STDC_CONSTANT_MACROS )
IF(MSVC)
    ADD_DEFINITIONS( -D_CRT_SECURE_NO_WARNINGS )
ENDIF()

#IF(OPENCV_FOUND)
#    ADD_DEFINITIONS(-DHAVE_OPENCV)
#ENDIF()

IF(TIFF_FOUND)
    ADD_DEFINITIONS(-DHAVE_TIFF)
    INCLUDE_DIRECTORIES( ${TIFF_INCLUDE_DIR} )
    LIST(APPEND EXTRA_LIBS ${TIFF_LIBRARY})
ELSE()
    LIST(REMOVE_ITEM sources io_tiff.cpp)
ENDIF()    

IF(MATLAB_FOUND)
    ADD_DEFINITIONS(-DHAVE_MATLAB)
    INCLUDE_DIRECTORIES( ${MATLAB_INCLUDE_DIR} )
    LIST(APPEND EXTRA_LIBS ${MATLAB_LIBRARIES})
ELSE()
    LIST(REMOVE_ITEM sources matfile.cpp matfile.h)
ENDIF()    

IF(WIN32)
    LIST(APPEND EXTRA_LIBS Dbghelp.lib)
ENDIF()

IF(LIBAV_FOUND)
    ADD_DEFINITIONS(-DHAVE_LIBAV)
    INCLUDE_DIRECTORIES( ${LIBAV_INCLUDE_DIR} )
    LIST(APPEND EXTRA_LIBS ${LIBAV_LIBRARIES} )
ELSE()
    LIST(REMOVE_ITEM sources ffmpeg_encoder.h ffmpeg_encoder.cpp ffmpeg_decoder.h ffmpeg_decoder.cpp )
ENDIF()

IF(CAIRO_FOUND)
    ADD_DEFINITIONS(-DHAVE_CAIRO)
    INCLUDE_DIRECTORIES( ${CAIRO_INCLUDE_DIR} )
    LIST(APPEND EXTRA_LIBS ${CAIRO_LIBRARY} )
ELSE()
    LIST(REMOVE_ITEM sources cairo_support.h cairo_support.cpp )
ENDIF()

CUDA_ADD_LIBRARY( liboz SHARED ${sources} )
SOURCE_GROUP( src REGULAR_EXPRESSION "c$|cpp$|hpp$|h$|ui$|qrc$|cu$" )
SET_TARGET_PROPERTIES( liboz PROPERTIES PREFIX "" )

TARGET_LINK_LIBRARIES( liboz 
    ${CUDA_npp_LIBRARY}
    ${CUDA_curand_LIBRARY}
    ${CUDA_cufft_LIBRARY}
    ${QT_LIBRARIES}
    ${EXTRA_LIBS} )

IF(LIBAV_FOUND)
	IF(WIN32)
		SET_TARGET_PROPERTIES( liboz PROPERTIES LINK_FLAGS "/OPT:NOREF" )
	ENDIF()
ENDIF()
